import { message } from 'ant-design-vue';
import { checkCreatSiteForm } from "./formRuler";
import { dataSourceType, } from "@/type.d";

// 不能输中文
const noChinese = (_rule: dataSourceType, value: string, callback: () => {}, type = 'noChinese', msg = '只能输入数字、大小写字母和特殊字符', useValue: number = 0) => {
  if (_rule.required) {// 必填项验证非空并排除非必须项
    if (!useValue) { // 使用fullField校验
      if ((value === '' || value === null || value === undefined)) {
        return Promise.resolve();
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.reject(`${_rule.msg1}`);
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    }
  } else {
    if (!useValue) {
      if ((value === '' || value === null || value === undefined)) {
        return Promise.resolve();
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.resolve();
      } else {
        const reg = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/g;
        return !reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg}`);
      }
    }
  }
}
// isBoolean:true, // 是否为Boolean类型, 参数是否必须为boolen类型，不是根据options个数判断，是根据后台字段类型要求判断
const accountSafeForm = [
  {
    value: "密码安全",
    type: "title",
    id: "pwdSecuritySetup",
    children: [
      {
        minValue: "",
        maxValue: "",
        param1: "minLength",
        param2: "maxLength",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "登录密码长度设置:",
        minBeforeText: "最短为",
        minAfterText: "位",
        maxBeforeText: "最长为",
        maxAfterText: "位",
        type: "mulNumberInput",
        associated: "",
        associatedValue: "",
      },
      {
        value: "",
        placeholder: "请选择",
        param: "generationRule",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "1111",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "密码规则校验:",
        extra: "",
        beforeText: "",
        afterText: "",
        type: "multipleSelect",
        options: [
          "不需要校验密码规则",
          "密码必须包含数字和字母",
          "密码必须包含数字和大小写字母",
          "密码必须包含数字、字母和特殊符号（!#%+-=/[]{}）",
          "密码必须包含数字、大小写字母和特殊符号（!#%+-=/[]{}）",
        ],
        mode: "single",
        associated: "",
        associatedValue: "",
      },
      {
        value: false,
        param: "allowNameEqPwd",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "是否允许用户名与密码相同:",
        type: "radio",
        isBoolean: true, // 是否为Boolean类型
        options: ["是", "否"],
        tips: "",
      },
      {
        value: false,
        param: "forceRegularChangePwd",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "是否强制要求用户定期修改密码:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      {
        value: "",
        param: "regularChangePwdDays",
        rule: {
          required: true,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "强制修改密码周期:",
        beforeText: "",
        afterText: "天",
        extra: "密码过期后登录系统，锁定密码修改页面，无法操作其他内容",
        type: "numberInput",
        associated: "forceRegularChangePwd",
        associatedValue: true,
      },
      {
        value: false,
        param: "forceLoginWithVerificationCode",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "登录是否强制需要验证码:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      {
        value: false,
        param: "forceChangePwdFirstLogin",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "首次登录是否强制要求修改密码:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      {
        value: false,
        param: "forceChangePwdAfterResetPwd",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "管理员重置密码后首次登录是否要求修改密码:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      {
        value: false,
        param: "enableWeakPwdCheck",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "是否开启弱密码检测:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      {
        value: 1,
        param: "handlerType",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "弱密码处理方式:",
        type: "radio",
        options: ["仅提示，可保存密码", "提示并无法保存密码"],
        isBoolean: false, // 是否为Boolean类型
        tips: "",
        associated: "enableWeakPwdCheck",
        associatedValue: true,
      },
      {
        value: "",
        placeholder: "请输入弱密码",
        param: "blacklist",
        rule: {
          required: true,
          validator: noChinese,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "",
        beforeText: "",
        afterText: "",
        inputType: "password",
        extra: "每个弱密码须单独一行，可输入数字、大小写字母和特殊字符",
        type: "textArea",
        associated: "enableWeakPwdCheck",
        associatedValue: true,
        isReset: true,
      },
      /*system-sm-crypto start*/
      {
        value: 0,
        param: "pwdEncodeType",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "密码加密方式:",
        type: "radio",
        isBoolean: false, // 是否为Boolean类型
        options: [],
      },
      /*system-sm-crypto end*/
      {
        value: "",
        placeholder: "请输入初始密码",
        param: "",
        rule: {
          required: true,
          //validator: checkCreatSiteForm,
          trigger: ["blur"],
          message: '初始密码不能为空！',
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "设置初始密码:",
        beforeText: "",
        afterText: "",
        type: "textInput",
        associated: "pwdEncodeType",
        associatedValue: 2,
        tips: "更改加密方式后，现有的前后台用户的密码都将被重置为此密码，初始密码不超过20位",
      },

    ],
  },

  {
    value: "登录安全",
    type: "title",
    id: "userLoginSecuritySetup",
    children: [
      {
        value: "",
        placeholder: "",
        param: "pwdErrorCount",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "密码输入错误最多次数:",
        beforeText: "",
        afterText: "次",
        type: "numberInput",
        associated: "",
        associatedValue: "",
        tips: "不填则视为不限制错误次数",
      },
      {
        value: "",
        placeholder: "请输入",
        param: "pwdErrorCountResetPeriod",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "1111",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "密码输入错误次数重置周期:",
        extra:
          "即当密码输入错误计数，在多少周期内会被重新计算。例如在24小时内，可输错三次。用户从第一次输错2次后，在24小时后，已输错的次数将被重置成0.",
        beforeText: "",
        afterText: "",
        stringMode: false,
        type: "selecteNumberInput",
        options: [{ label: "分钟", value: 2 }, { label: "小时", value: 3 }, { label: "天", value: 4 }],
        optionsValue: 2,
        params_options: "pwdErrorCountResetTimeUnit",
        associated: "",
        associatedValue: "",
      },
      {
        value: 1,
        placeholder: "请选择",
        param: "loginErrorHandleType",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "1111",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "密码错误超出限制后，处理方式:",
        extra: "",
        beforeText: "",
        afterText: "",
        type: "multipleSelect",
        options: ["图形验证码验证", "禁止登录", "一段时间内禁止登录"],
        mode: "single",
      },
      {
        value: "",
        placeholder: "请输入",
        param: "disableAccoutTime",
        rule: {
          required: true,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "1111",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "禁止登录时长:",
        extra: "建议禁止登录时长大于等于密码重置周期时长",
        beforeText: "",
        afterText: "",
        stringMode: false,
        type: "selecteNumberInput",
        options: [{ label: "分钟", value: 2 }, { label: "小时", value: 3 }, { label: "天", value: 4 }],
        optionsValue: 1,
        marginLeft: 32,
        params_options: "disableAccoutTimeUnit",
        associated: "loginErrorHandleType",
        associatedValue: 3,
      },
      {
        value: true,
        param: "tokenExpired",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "长时间未操作需重新登录:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      {
        value: "",
        placeholder: "请输入",
        param: "tokenTimeout",
        rule: {
          required: true,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "1111",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "未操作系统时长设置:",
        extra: "",
        beforeText: "",
        afterText: "分钟",
        stringMode: false,
        type: "numberInput",
        associated: "tokenExpired",
        associatedValue: true,
      },
      {
        value: true,
        param: "supportMutiLogin",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "是否允许同一账号多地登录:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "",
      },
      /*system-double start*/
      {
        value: false,
        param: "enableDubbleFactorCheck",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "是否开启双因子登录认证:",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
      },
      /*system-double end*/
      {
        value: 1,
        param: "smsVerificationCodeLength",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "短信验证码长度:",
        type: "radioButton",
        options: ["4位", "6位", "8位"],
        optionsValue: 1,
        isBoolean: false, // 是否为Boolean类型
        associated: "enableDubbleFactorCheck",
        associatedValue: true,
      },
      {
        value: "",
        param: "smsVerificationCodeTtl",
        rule: {
          required: true,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "短信验证码有效期:",
        beforeText: "",
        afterText: "分钟",
        type: "numberInput",
        associated: "enableDubbleFactorCheck",
        associatedValue: true,
      },
    ],
  },

  {
    value: "账户安全",
    type: "title",
    id: "accoutSecuritySetup",
    children: [
      {
        value: false,
        param: "disableAccoutNoLoginLongTime",
        rule: {
          required: false,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "长期未登录锁定账号:",
        extra: "长期未登录用户状态将自动变为禁用状态",
        type: "radio",
        options: ["是", "否"],
        isBoolean: true, // 是否为Boolean类型
        tips: "禁用的用户可以在【用户管理】中启用",
      },
      {
        value: "",
        param: "noLoginTime",
        rule: {
          required: true,
          validator: checkCreatSiteForm,
          trigger: ["blur"],
          msg1: "",
          msg2: "",
          api: "",
          key: "siteDomain",
          params: {}, //校验传参
        },
        label: "长期未登录时间:",
        beforeText: "",
        afterText: "天",
        type: "numberInput",
        associated: "disableAccoutNoLoginLongTime",
        associatedValue: true,
      },
    ],
  },
];
export { accountSafeForm };
